<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script type=" text/javascript">
function loadXMLDoc(){
	var xmlhttp;
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}
function jump() {
		var ajax;
		ajax = loadXMLDoc();
		ajax.open("POST", "addgoodservlet", true);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				var result = ajax.responseText;
				if (result == "2") {
					alert("添加成功");
				} else if(result=="1"){
					document.getElementById("mypd").innerHTML = "请认真填写表格";
				}else{
					document.getElementById("mypd").innerHTML = "商品编号已存在";
				}
			}
		}
		ajax.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded");
		var tradename=document.getElementById("tradename").value;
		var productId =document.getElementById("productId").value;
		var number=document.getElementById("number").value;
		var money=document.getElementById("money").value;
		var class_=document.getElementById("class_").value;
		var location = document.getElementById("location").value;
		ajax.send("tradename=" + tradename + "&productId=" + productId+
"&number=" + number + "&money=" + money+ "&class_=" + class_+ "&location=" + location);
	}

	</script>
	<style>
       .setbg{
    		border: 0px none;
    		height: 80%;
    		width:80%;
    		background-repeat: no-repeat;
    		background-size: 100%;
    	}
        </style>
        
  </head>
  
  <body>
     <div class="setbg"><div class="panel panel-default">
	<div class="panel-heading">
		<h3 class="panel-title">超市仓库管理系统</h3>
	</div>
		
		<div class="panel-body">
		添加商品
	</div>
	
<form class="form-horizontal" role="form" action="">
	<div class="form-group">
		<label for="firstname" class="col-sm-2 control-label">商品名称</label>
		<div class="col-sm-10">
			<input type="text" class="form-control" id="tradename" name="tradename" />
		</div>
	</div>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">商品类别</label>
		<div class="col-sm-10">
			<input type="text" class="form-control" id="class_" name="class_" />
		</div>
	</div>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">商品编号</label>
		<div class="col-sm-10">
			<input type="text" class="form-control" id="productId" name="productId" />
		</div>
	</div>
	<div class="form-group">
		<label for="lastname"class="col-sm-2 control-label">商品数量</label>
		<div class="col-sm-10">
			<input type="text" class="form-control" id="number"  name="number" />
		</div>
	</div>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">商品单价</label>
		<div class="col-sm-10">
			<input type="text" class="form-control"  id="money" name="money" />
		</div>
	</div>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">商品位置</label>
		<div class="col-sm-10">
			<input type="text" class="form-control"  id="location" name="location" />
		</div>
	</div>
	<div id="mypd"></div>
	<div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			<button type="button" class="btn btn-default" id="mybt" value="提交" onclick="jump()">添加</button>
			<button type="reset" class="btn btn-default">重置</button>
		</div>
	</div>
</form>
	</div>
     
     </div>
  </body>
</html>
